# interface of variance decomposition method
# 
# @population: an object of 'population' class.
# @covariances: a list of 'im' objects which contain covariance variable
# @select: logical, if it is TRUE, covariables will be selected by back-ward selection method
# @models: list of model's name. the options of reconigzed model names are 'Poisson', 'LGCP', 'Thomas'
#
# Author: guochun
###############################################################################


varianceDecomposite=function(population,covariances,select,models=list("LGCP"),
		alpha=0.05,pvalue=TRUE,nu=1/2){

	#construct modeling objects
	modelingObjects=constructModel(population, covariances,select,pvalue,models,nu=nu)
	
	if(nu==0){
		nu=selectnu(modelingObjects)
		modelingObjects@nu=nu
	}
	
	#p-values for covariance and aggregative parameters
	re.m=agModeling(modelingObjects)
	
	if(select){
		#select covariables if neissary and calculate global pvalue
		re.m=backwardSelecter(re.m,alpha=alpha,nu)
		#re.m=mutliBackwardSelecter(re.m,alpha=alpha,nu)
	}
	
	#check whether is there any significant aggregative pattern left in residual
	if(pvalue)
	    re.m=agregativeResidualTest(re.m,nsim=100)
	
	#calcuate tildeZ and tildeY, construct result object
	result=constructResult(re.m)
	
	return(result)
}
